using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using MemberMgr.Data.ManagerObjects;
using MemberMgr.Data.BusinessObjects;
using MemberMgr.Data.Base;

namespace MemberMgr.Data.UnitTests
{
	[TestFixture]
    public partial class tMenuTests : UNuitTestBase
    {
        protected ItMenuManager manager;
		
		public tMenuTests()
        {
            manager = managerFactory.GettMenuManager();
        }
		
		protected tMenu CreateNewtMenu()
		{
			tMenu entity = new tMenu();
			
			
			entity.Menuno = "Test Test ";
			entity.Menuname = "Test Test ";
			entity.Menuurl = "Test Test ";
			entity.Menuico = "Test Test ";
			entity.Menulevel = "Test Test ";
			entity.Menuparent = default(UInt32);
			
			return entity;
		}
		protected tMenu GetFirsttMenu()
        {
            IList<tMenu> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				tMenu entity = CreateNewtMenu();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                tMenu entityA = CreateNewtMenu();
				manager.Save(entityA);

                tMenu entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                tMenu entityA = GetFirsttMenu();
				
				entityA.Menuno = "Test Test ";
				
				manager.Update(entityA);

                tMenu entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Menuno, entityB.Menuno);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                tMenu entity = GetFirsttMenu();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

